﻿using System;

public class List
{
    class Program
    {
        public static DataSet ExcelToDataSet(string filename)  //函数用来读取一个excel文件到DataSet集中  
        {
            string strCon = "Provider=Microsoft.Jet.OLEDB.4.0;" +
                            "Extended Properties=Excel 8.0;" +
                            "data source=" + filename;
            OleDbConnection myConn = new OleDbConnection(strCon);
            string strCom = " SELECT * FROM [qq1$]";    //"qq1"为表单标签页名  
            myConn.Open();
            OleDbDataAdapter myCommand = new OleDbDataAdapter(strCom, myConn);
            DataSet ds;
            ds = new DataSet();
            myCommand.Fill(ds);
            myConn.Close();
            return ds;
        }
        static void Main(string[] args)
        {
            DataSet ds = ExcelToDataSet("~/图书信息导入.xls");           //括号中为表格地址  
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                string str = ds.Tables[0].Rows[i]["周一"].ToString(); //Rows[i]["col1"]表示i行"col1"字段  
                Console.WriteLine(str);
            }
            Console.WriteLine("Hello world, 前面正确执行...");
            Console.ReadKey();
        }
    }
}
